﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;

namespace KINLO.UI.Main.Converter
{
    public class IsGoodsBackgroundConverter:IValueConverter
    { 
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                if (value is null)
                {
                    return Brushes.Transparent;
                }

                int count;
                if (int.TryParse(value.ToString(), out count))
                {
                    switch (count)
                    {
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                        case 6:
                        case 7:
                            return Brushes.Red;
                        default:
                            return Brushes.Green;
                    }
                }
                else
                {
                    return value;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return value;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        } 
    }
}
